import requests

# url = 'https://hackpython.com'
# r = requests.get(url)
# print(r.status_code)
# print(r.text)

url = 'https://baidu.com'
# 构建请求头字典
headers = {
    'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.92 Safari/537.36'
}
r = requests.get(url, headers=headers)
with open('baidu.html', 'w') as f:
    f.write(r.text)